import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router"
import MyMusic from "./views/MyMusic.vue"
import FindMusic from "./views/FindMusic.vue"
import Ranking from "./views/Child/Ranking.vue"
import SongList from "./views/Child/SongList.vue"
import Recommend from "./views/Child/Recommend.vue"
Vue.config.productionTip = false
Vue.use(VueRouter)
const routes = [{
    path: "/",
    redirect: "/findmusic"
  },
  {
    path: "/findmusic",
    component: FindMusic,
    children: [{
      path: "recommend",
      component: Recommend
    }, {
      path: "ranking",
      component: Ranking
    }, {
      path: "songlist",
      component: SongList
    }]
  },
  {
    path: "/mymusic",
    component: MyMusic
  }
]
const router = new VueRouter({
  routes: routes
})
new Vue({
  router,
  render: h => h(App),

}).$mount('#app');
// 假定登录状态
let login = true;
router.beforeEach((to, from, next) => {
  //to and from are Route Object,next() must be called to resolve the hook}
  if (to.path == "/mymusic" && login == false) alert('login please')
  else next();
})